package com.qfedu.video.service.impl;


import com.github.pagehelper.PageHelper;
import com.qfedu.video.entry.DeleteVideoVo;
import com.qfedu.video.entry.Video;
import com.qfedu.video.entry.VideoVo;
import com.qfedu.video.mapper.SpeakerMapper;
import com.qfedu.video.mapper.VideoMapper;
import com.qfedu.video.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class VideoServiceImpl implements VideoService {


    @Autowired
    VideoMapper videoMapper;

    @Autowired
    SpeakerMapper speakerMapper;



    public List<Video> getVideoAll() {

        List<Video> list =videoMapper.selectVideoAll();

        return list;
    }

    public List<Video> getVideos(VideoVo videoVo) {

        //需要在service中添加一个PageHelper的方法
        PageHelper.startPage(videoVo.getPage(),videoVo.getSize());
        // select * from video limit 10,20
        List<Video> list =videoMapper.selectVideoByTj(videoVo);
        System.out.println(list);

        return list;
    }

    public int deleteBatchByIds(Integer[] ids) {

        DeleteVideoVo videoVo=new DeleteVideoVo();
        //Arrays.asList 可以快速的将一个数组转换为list集合，但是该集合不允许添加和删除
        List<Integer> list =Arrays.asList(ids);
        videoVo.setIds(list);
        int result =videoMapper.deleteBatchByIds(videoVo);

        return result;
    }

    public void saveOrUpdate(Video video) {


        if(video.getId()==0){
            //新增
            videoMapper.save(video);
        }else{
            //修改
            videoMapper.update(video);
        }
    }

    public Video getVideoById(int id) {

        Video video = videoMapper.getVideoById(id);
        return  video;
    }

    public List<Video> getVideoListByCourseId(int courseId){
       return videoMapper.getVideoListByCourseId(courseId);
    }
}
